package com.generate.span;


import com.generate.table.Table;
import com.generate.table.Td;
import com.generate.table.Tr;

import java.util.List;
import java.util.Map;

public class DefaultSpanCallBack implements SpanCallBack {

    @Override
    public void build(Table table) {
        if (table == null) {
            return;
        }
        table.clear();
        Tr tr = new Tr();
        List<Table.Cell> cells = table.getCells();
        for (Table.Cell cell : cells) {
            Td td = new Td();
            td.setTitle(cell.getField());
            tr.addTd(td);
        }
        table.addTr(tr);
        List<Map<String, String>> tableData = table.getTableData();
        for (Map<String, String> tableDatum : tableData) {
            tr = new Tr();
            for (Table.Cell cell : cells) {
                Td td = new Td();
                td.setTitle(tableDatum.get(cell.getProp()));
                tr.addTd(td);
            }
            table.addTr(tr);
        }
    }
}
